package com.hou.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hou.mapper.SeckillApplicationFormMapper;
import com.hou.parma.PageParam;
import com.hou.pojo.SeckillApplicationForm;
import com.hou.service.ISeckillApplicationFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author jack
 * @since 2022-04-02
 */
@Service
public class SeckillApplicationFormServiceImpl extends ServiceImpl<SeckillApplicationFormMapper, SeckillApplicationForm> implements ISeckillApplicationFormService {
    @Autowired
    SeckillApplicationFormMapper seckillApplicationFormMapper;


    @Override
    public SeckillApplicationForm select(Long id) {
        SeckillApplicationForm seckillApplicationForm = seckillApplicationFormMapper.selectById(id);
        return seckillApplicationForm;
    }

    @Override
    public Long selects(String name) {
        Long aLong = seckillApplicationFormMapper.selectCount(new QueryWrapper<SeckillApplicationForm>().like("username",name));
        return aLong;
    }

    @Override
    public Long select1() {
        Long aLong = seckillApplicationFormMapper.selectCount(new QueryWrapper<SeckillApplicationForm>());
        return aLong;
    }

    @Override
    public List<SeckillApplicationForm> selectList(PageParam pageParam) {
        List<SeckillApplicationForm> date = seckillApplicationFormMapper.selectPage(new Page<>(pageParam.getCurrentPage(), pageParam.getPageSize()), null).getRecords();

        return date;
    }

    @Override
    public List<SeckillApplicationForm> selectList_Asc(PageParam pageParam) {
        List<SeckillApplicationForm> date = seckillApplicationFormMapper.selectPage(new Page<>(pageParam.getCurrentPage(), pageParam.getPageSize()), new QueryWrapper<SeckillApplicationForm>().select().orderByAsc("date")).getRecords();
        return date;
    }

    //(List) list.selectPage(new Page<>(pageParam.getCurrentPage(), pageParam.getPageSize()), objectQueryWrapper.select().orderByAsc("date")).getRecords();
    @Override
    public List<SeckillApplicationForm> selectList_Desc(PageParam pageParam) {
        List<SeckillApplicationForm> date = seckillApplicationFormMapper.selectPage
                (new Page<>(pageParam.getCurrentPage(), pageParam.getPageSize()),
                        new QueryWrapper<SeckillApplicationForm>()
                                .select().orderByDesc("date")).getRecords();
        return date;
    }

    @Override
    public List<SeckillApplicationForm> selectList_ByName(PageParam pageParam, String name) {
        List<SeckillApplicationForm> date = seckillApplicationFormMapper.selectPage
                (new Page<>(pageParam.getCurrentPage(), pageParam.getPageSize()),
                        new QueryWrapper<SeckillApplicationForm>().or()
                                .like("username", name)).getRecords();
        return date;
    }

    @Override
    public List<SeckillApplicationForm> selectList_ByPass(PageParam pageParam) {
        List<SeckillApplicationForm> date = seckillApplicationFormMapper.selectPage
                (new Page<>(pageParam.getCurrentPage(), pageParam.getPageSize()),
                        new QueryWrapper<SeckillApplicationForm>()
                                .eq("pass",true)).getRecords();
        return date;
    }

    @Override
    public List<SeckillApplicationForm> selectList_ByFaile(PageParam pageParam) {
        List<SeckillApplicationForm> date = seckillApplicationFormMapper.selectPage
                (new Page<>(pageParam.getCurrentPage(), pageParam.getPageSize()),
                        new QueryWrapper<SeckillApplicationForm>()
                                .eq("pass",false)).getRecords();
        return date;
    }
}
